#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v={1,2,3,8,6,7};
vector<int> copys(v);
void merge(vector<int>& data,vector<int>& copys,int low,int high){
    if(low>=high) return;
    int mid=low+(high-low)/2;
    int low1=low,high1=mid,low2=mid+1,high2=high,index=low;
    merge(copys,data,low1,high1);
    merge(copys,data,low2,high2);
    while(low1<=high1&&low2<=high2){
        copys[index++]=data[low1]<data[low2]?data[low1++]:data[low2++];
    }
    while(low1<=high1){
        copys[index++]=data[low1++];
    }
    while(low2<=high2){
        copys[index++]=data[low2++];
    }
}

int main(){
    merge(v,copys,0,v.size()-1);
    for_each(v.begin(),v.end(),[](int num){
        cout<<num<<" ";
    });
    cout<<endl;
    return 0;
}